package com.up.upzl.biz.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.up.upzl.biz.domain.Area;
import com.up.upzl.biz.service.AreaService;

/**
 * 地区控制器
 * 
 * @author joker
 *
 */
@Controller
@RequestMapping("area")
public class AreaController {
	@Autowired
	private AreaService areaService;

	/**
	 * 根据父级ID查找城市
	 */
	@PostMapping("findArea")
	public @ResponseBody List<Area> findArea(@Param("parentId") Long parentId) {
		if (parentId == null) {
			return null;
		}
		List<Area> list = areaService.findByParentId(parentId);
		if (list == null) {
			return null;
		}
		return list;
	}

	/**
	 * 查找城市
	 */
	@PostMapping("findCity")
	public @ResponseBody List<Area> findCity() {
		List<Area> list = areaService.findByParentId(null);
		if (list == null) {
			return null;
		}
		return list;
	}
}
